import express from 'express'
import { Request, Response } from 'express'
import Video from "../video/video"
import { successMessage, errorMessage } from "../resTip/resTip"

const router = express.Router()

router.get("/search",async (req:Request,res:Response)=>{
  let from = parseInt(req.query.from as string)
  let size = parseInt(req.query.size as string)
  let data =await new Video.searchAllVideo(from,size).search()
  data.length>0?res.json(new successMessage(data)):res.json(new errorMessage("数据获取失败"))
})
router.get("/del",async (req:Request,res:Response)=>{
  let id = parseInt(req.query.id as string)
  let data =await new Video.delVideo(id as number).del()
  data.affectedRows?res.json(new successMessage("删除成功")):res.json(new errorMessage("删除失败"))
})
router.get("/category",async (req:Request,res:Response)=>{
  let category = req.query.category
  let from = parseInt(req.query.from as string)
  let size = parseInt(req.query.size as string)
  let data = await new Video.filterCategoryVideo(category as string,from,size).filterForCategory()
  data.length>0?res.json(new successMessage(data)):res.json(new errorMessage("数据获取失败"))
})
router.get("/name",async (req:Request,res:Response)=>{
  let name = req.query.name
  let data = await new Video.filterNameVideo(name as string).filterForName()
  data.length>0?res.json(new successMessage(data)):res.json(new errorMessage("数据获取失败"))
})
router.get("ccount",async (req:Request,res:Response)=>{
  let name = req.query.name
  let currentCount = req.query.currentCount
  let data = await new Video.filterCurrentCountVideo(currentCount as string,name as string).filterForCurrentCount()
  data.length>0?res.json(new successMessage(data)):res.json(new errorMessage("数据获取失败"))

})

export default router